﻿@{
    ViewData["Title"] = "Home Page";
}




<div id="output"></div>

@section Scripts
{
<script language="javascript" type="text/javascript">
    var socket;
    var uri = "ws://" + window.location.host + "/ws";
    var output;
    var text = "test echo";

    function write(s) {
        var p = document.createElement("p");
        p.innerHTML = s;
        output.appendChild(p);
    }

    function doConnect() {
        socket = new WebSocket(uri);
        socket.onopen = function (e) {
            write("opened " + uri);
            //doSend();
        };
        socket.onclose = function (e) {
            write("closed");
        };
        socket.onmessage = function (e) {
            write("Received: " + e.data);
            //socket.close();
        };
        socket.onerror = function (e) {
            write("Error: " + e.data);
        };
    }

    function doSend() {
        write("Sending: " + text);
        socket.send(text);
    }

    function onInit() {
        output = document.getElementById("output");
        doConnect();
    }

    //window.onload = onInit;

    $.post("/auth/token", { username: "Member", password:"123"}, function (result) {
        if (result) {
            console.log(result);
        }
    }, "json");


</script>
}